package com.formina.stars;

import javax.microedition.khronos.opengles.GL10;

import com.formina.engine.Effect;
import com.formina.engine.Model;

import android.util.FloatMath;


public class Confetti extends Effect{
	
	int addstarsCount = 0;
	
	public Confetti(float[] location, float[] scale) {
		super(location, scale);
		this.AddStars();
		/*
		Star a = new Star(location, new float[]{.2f,.2f,.2f});
		a.setLocation(a.getX()+100f, location[1], 1f);
		particles.add(a);
		Star b = new Star(location, new float[]{.2f,.2f,.2f});
		b.setLocation(b.getX()+300f, location[1], 1f);
		particles.add(b);
		*/
	}
	
	void AddStars(){
		float cos, sin,zcos, scale;
		scale = 10f;
		for(float d=0;d<360;d+=20){
			StarParticle x = new StarParticle(Location(), new float[]{scale,scale,scale});
			x.setDirection(d);
			cos = FloatMath.cos(Model.ToRadians(d));
			sin = FloatMath.sin(Model.ToRadians(d));
			zcos = 0f;
			x.setVelocity(new float[]{cos, sin, zcos});
			particles.add(x);
		}
		this.addstarsCount++;
	}
	
	@Override
	public void update(long time){

		if(started == 0){
			started = time;
		}
		boolean alldead = true;
		Model p;
		for(int x= particles.size()-1; x>=0;x--){
			p = particles.get(x);
			p.update(time);
			if(!p.IsDead()){
				alldead = false;
			}
		}
		if(alldead){
			isDead = true;
		}
		
		
	}
	
	@Override
	public void draw(GL10 gl){
		for(int x= particles.size()-1; x>=0;x--){
			//Log.d("ix", String.valueOf(x)+" - " + String.valueOf(particles.get(x).getX()));
			particles.get(x).draw(gl);
		}
	}

}
